<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0,user-scalable=no" />
		<title>获取当前位置的地理信息示例</title>
		<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
		<script type="text/javascript">
				
			function get_location(){
				if(navigator.geolocation){
					navigator.geolocation.getCurrentPosition(show_map,handle_error,{enableHighAccuracy:true,maximumAge:1000});
				}else{
					alert('你的浏览器不支持使用 HTML5 来获取地理位置信息。');
				}
			}
			
			function show_map(position){
				var latitude = position.coords.latitude;
				var longitude = position.coords.longitude;
				showObject(position,0);
			}
			
			function showObject(obj,k){
				if(!obj){return;}
				for(var i in obj){
					if(typeof(obj[i])!="object" || obj[i]==null){
						for(var j=0;j<k;j++){
							document.write("&nbsp;&nbsp;&nbsp;&nbsp;");
						}
						document.write(i+":"+obj[i]+"<br/>");
					}else{
						document.write(i + ":" + "<br/>");
						showObject(obj[i],k+1);
					}
				}
			}
			
			
			function handle_error(err){
				switch(err.code){
					case 1:
						alert("位置服务被拒绝。");
						break;
					case 2:
						alert("暂时获取不到位置信息。");
						break;
					case 3:
						alert("获取信息超时。");
						break;
					case default:
						alert("未知错误。");
						break;
				}
			}
			
			
			
			get_location();
		</script>
	</head>
	<body>
		<div id="map" style="width: 400px;height: 400px;"></div>
	</body>
</html>
